//
//  LCShowComposeViewNoImagesCell.swift
//  JKBiblicalReading
//
//  Created by admin on 2018/8/20.
//  Copyright © 2018年 LC. All rights reserved.
//

import UIKit
import SDAutoLayout

class LCShowComposeViewNoImagesCell: LCSendSugarListBaseTableCell {
        var model: LCShowComposeModel? {
            didSet{
//                print(model ?? "");
                contentLabel.text = model?.content
                imageUrl = model?.avatar
                usernameButton.setTitle(model?.username, for: .normal)
                let addtime : String = LCUtils.lcGetThePreviousTime(withGetTime: model?.addtime)
                addtimeButton.setTitle(addtime, for: .normal)
                //点赞
                followButton.setTitle("\(model?.admire_num ?? 0)" , for: .normal)
//                ///评论
//                pingLunButton.setTitle("  " + (model?.comment_num ?? "") , for: .normal)
//                ///点赞
//                zanButton.setTitle("  " + (model?.admire_num ?? "") , for: .normal)
                showComposePictureView.imageList = model?.images ?? []
                showComposePictureView.reloadData()
            }
        }
    
        var imageUrl: String? {
            didSet{
                authorImageView.image = UIImage(named: "作者简介_默认")
                if imageUrl == nil || imageUrl == "" {
                }else{
                    let urlstr = URL(string: imageUrl!)
                    authorImageView.sd_setImage(with: urlstr, completed: nil)
                }
            }
        }
        //
        //    //FIXME:-告知删除对应的图片
        //    var closeEvent:(()->())?
        
        //FIXME:- 上午10:29 设置视图
        ///设置视图
        override func setupUI(){
            //        backgroundColor = randomColor()//UIColor(white: 235 / 255, alpha: 1)
            contentView.addSubview(authorImageView)
            authorImageView.snp.makeConstraints { (make) in
                make.left.top.equalTo(contentView).offset(15)
                make.width.height.equalTo(55)
            }
            contentView.addSubview(usernameButton)
            contentView.addSubview(followButton)
            usernameButton.snp.makeConstraints { (make) in
                make.top.equalTo(self.authorImageView.snp.top)
                make.left.equalTo(self.authorImageView.snp.right).offset(15)
                make.height.equalTo(30)
                make.right.equalTo(self.followButton.snp.left).offset(0)
            }
            followButton.snp.makeConstraints { (make) in
                make.top.equalTo(usernameButton.snp.top)
                make.right.equalTo(contentView.snp.right).offset(-20)
                make.height.equalTo(22)
                make.width.equalTo(46)
            }
            
            contentView.addSubview(addtimeButton)
            addtimeButton.snp.makeConstraints { (make) in
                make.top.equalTo(self.usernameButton.snp.bottom)
                make.left.equalTo(self.usernameButton.snp.left).offset(0)
            }
            
            contentView.addSubview(contentLabel)
            contentLabel.snp.makeConstraints { (make) in
                make.top.equalTo(authorImageView.snp.bottom).offset(15)
                make.left.equalTo(usernameButton.snp.left).offset(0)
                make.right.equalTo(contentView.snp.right).offset(-15)
                make.height.equalTo(contentLabel.snp.height)
            }
            contentView.addSubview(pingLunButton)
            pingLunButton.snp.makeConstraints { (make) in
                make.top.equalTo(contentLabel.snp.bottom).offset(15)
                make.left.equalTo(usernameButton.snp.left).offset(0)
                make.width.greaterThanOrEqualTo(65)
            }
            contentView.addSubview(zanButton)
            zanButton.snp.makeConstraints { (make) in
                make.top.equalTo(pingLunButton.snp.top).offset(0)
                make.left.equalTo(pingLunButton.snp.right).offset(20)
                make.width.greaterThanOrEqualTo(65)
            }
            contentView.addSubview(举报Button)
            举报Button.snp.makeConstraints { (make) in
                make.top.equalTo(pingLunButton.snp.top).offset(0)
                make.right.equalTo(contentView.snp.right).offset(-20)
            }
            
            let margin: CGFloat = 20
            
            self.setupAutoHeight(withBottomView: zanButton, bottomMargin: margin)
            
        }
        fileprivate func followButtonState() {
            if self.followButton.isSelected == true {
                //self?.showMessage("按钮被点击选中")
                self.followButton.backgroundColor = UIColor(red:0.78, green:0.78, blue:0.78, alpha:1.00)
            }else{
                self.followButton.backgroundColor = redSystemColor()
            }
        }

        @objc fileprivate func followButtonClick(){
            print("点赞 \(followButton.isSelected)")
            self.followButton.isSelected = !(self.followButton.isSelected)
            self.followButtonState()
//            LCShowComposeViewModel.clickButFocus(onDetaill: model?.uid, "\(followButton.isSelected)", success: {
//
//            }) { (str) in
//                if str == "未登录" {
//
//                }
//            }
        }
        @objc fileprivate func titleButtonClick(){
            print("用户信息")
            
        }
        @objc fileprivate func addtimeButtonClick(){
            print("add时间")
            
        }
        @objc fileprivate func pingLunButtonClick(){
            print("评论")
            
        }
        @objc fileprivate func zanButtonClick(){
            print("点赞")
            
        }
        @objc fileprivate func shareButtonClick(){
            print("举报")
            let actionSheet: ACActionSheet = ACActionSheet(title: nil, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: ["举报"], actionSheetBlock: { (buttonIndex: Int) in
                if buttonIndex == 0 {
                    // LSZReportViewController * VC = [[LSZReportViewController alloc]init];
                    // VC.name = manager.username;
                    // VC.titleString = manager.content;
                    // VC.tid = manager.id_id;
                    // VC.type = @"1";
                    // VC.comment_id = @"";
                    // [self.navigationController pushViewController:VC animated:YES];
                }
                
            })
            actionSheet.show()

        }
        //
        //FIXME:- 懒加载控件
        lazy var authorImageView:UIImageView = {
            let authorImageView : UIImageView = UIImageView()
            authorImageView.layer.masksToBounds = true
            // 设置圆角大小
            authorImageView.layer.cornerRadius = 55.0/2
            authorImageView.contentMode = .scaleAspectFill;
            authorImageView.clipsToBounds = true;
            
            return authorImageView
        }()
        
        lazy var contentLabel : UILabel = {
            let label: UILabel = UILabel()
            label.textColor = UIColor.darkGray
            label.numberOfLines = 0
            label.font = UIFont.systemFont(ofSize: 18)
            label.textAlignment = .left
            label.backgroundColor = UIColor.clear
            return label
        }()
        
        lazy var usernameButton: UIButton = {
            let button = UIButton()
            LCUtils.didChangeButtonLeft(forAlignment: button)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 22)
            button.addTarget(self, action: #selector(titleButtonClick), for: .touchUpInside)
            button.setTitleColor(UIColor.black, for: .normal)
            button.setTitle("用户昵称", for:.normal)
            return button
        }()
        
        lazy var addtimeButton: UIButton = {
            let button = UIButton()
            button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
            button.addTarget(self, action: #selector(addtimeButtonClick), for: .touchUpInside)
            button.setTitle("发布时间", for:.normal)
            button.setTitleColor(UIColor.lightGray, for: .normal)
            return button
        }()
        lazy var pingLunButton: UIButton = {
            let button = UIButton()
            button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
            button.addTarget(self, action: #selector(pingLunButtonClick), for: .touchUpInside)
            //留言
            button.setImage(UIImage(named: "留言"), for: .normal)
            button.setTitleColor(UIColor.lightGray, for: .normal)
            button.contentHorizontalAlignment = .left;
            return button
        }()
        lazy var zanButton: UIButton = {
            let button = UIButton()
            button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
            button.addTarget(self, action: #selector(zanButtonClick), for: .touchUpInside)
            //点赞
            button.setImage(UIImage(named: "弹窗-点赞"), for: .normal)
            //点赞完
            button.setImage(UIImage(named: "点赞完"), for: .selected)
            button.setTitleColor(UIColor.lightGray, for: .normal)
            button.contentHorizontalAlignment = .left;
            return button
        }()
        lazy var 举报Button: UIButton = {
            let button = UIButton()
            button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
            button.addTarget(self, action: #selector(shareButtonClick), for: .touchUpInside)
            //分享
            button.setImage(UIImage(named: "动态_更多点"), for: .normal)
            button.setTitleColor(UIColor.lightGray, for: .normal)
            return button
        }()
    
        lazy var followButton: UIButton = {
            let button = UIButton()
            button.isHidden = true
            button.backgroundColor = redSystemColor()
            button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
            button.addTarget(self, action: #selector(followButtonClick), for: .touchUpInside)
            button.setTitle("+关注", for:.normal)
            // 设置圆角大小
            button.layer.cornerRadius = 7
            button.contentMode = .scaleAspectFill;
            return button
        }()
    lazy var showComposePictureView: LCShowComposePictureView = {
        let view = LCShowComposePictureView()
        return view
    }()
}

